package test0ne.多线程;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入锁的使用
 */
public class ReentrantLockExample {
    int a = 0 ;
    ReentrantLock lock = new ReentrantLock();

    public void writer() {
        lock.lock();          //加锁
        try {
            a++;
        } finally {
            lock.unlock();    //释放锁
        }
    }

    public void reader() {
        lock.lock();         //加锁
        try {
            int i = a;
        } finally {
            lock.unlock();   //释放锁
        }
    }
}
